package com.lxl.edu.info.manager.service;

import com.lxl.edu.info.manager.controller.StudentController;
import com.lxl.edu.info.manager.dao.StudentDao;
import com.lxl.edu.info.manager.daomain.Student;


public class StudentSevice {
    private StudentDao studentDao = new StudentDao();

    public static Student[] findAllStudent() {
        StudentController studentController = new StudentController();
        Student[] allStudent = StudentDao.findAllStudent();
        return  allStudent;

    }


    public boolean addStudent(Student st) {
        //创建StudentDao（库管）
        // StudentDao studentDao = new StudentDao();

        //将学生对象，传递给StudentDao库管的addStudent方法
        //将返回的boolean类型结果，返还给StudentController
        return studentDao.addStudent(st);

    }

    //判断学号是否存在
    public boolean isExists(String id) {

        Student[] stus = StudentDao.findAllStudent();
        boolean exists = false;
        for (int i = 0; i < stus.length; i++) {
            Student student = stus[i];
            if (student != null && student.getId().equals(id)) {
                exists = true;
                break;
            }
        }

        return exists;

    }
}
